package com.cpimex.eprice.model.users;

import java.sql.Statement;
import java.util.*;
import java.sql.Connection;
import java.sql.*;
import com.cpimex.eprice.bean.EstatusBean;

public class VPO extends Usuario {
    public VPO() {
    }

    public ArrayList listado(Connection conn, String str_query2, Map map_where, int int_ordenar,
                             boolean bol_orderAsc) throws Exception {
        ArrayList arr_result = null;
        String str_query = super.str_query;

        str_query += " where ( estatus_sol in ('PENVPO', 'RCHZ-VPO') or ( estatus_sol = 'AUTORIZADA' and ( precio_sol < precioActual_sol or precio_sol < precioLista_sol ) ) ) ";

        String str_ejecutivo = map_where.get("str_ejecutivo")==null || map_where.get("str_ejecutivo").equals("") ?"":((String) map_where.get("str_ejecutivo"));
        String str_coord     = map_where.get("str_coord")==null || map_where.get("str_coord").equals("") ?"":((String) map_where.get("str_coord"));
        String str_gerente   = map_where.get("str_gerente")==null || map_where.get("str_gerente").equals("") ?"":((String) map_where.get("str_gerente"));

        str_query +=
                (str_ejecutivo.equals("")?"":" AND  " + " codigoVen_sol = '" + str_ejecutivo + "' ") +
                (str_coord.equals("")    ?"":" AND  " + " coordinadoraCli_sol = '" + str_coord + "' ") +
                // level 5 2009 09 05 R2-3 Actualizar referencias a tabla ep_claseProd por cambio de registros
                //(str_gerente.equals("")  ?"":" AND  " + " claseProducto_sol = '" + str_gerente + "' ");
                (str_gerente.equals("")  ?"":" AND  " + " codigoDivision_detSol = '" + str_gerente + "' ");

        arr_result = super.listado(conn, str_query, map_where, int_ordenar, bol_orderAsc);
        return arr_result;
    }

    public ArrayList listarEstatus(Connection conn) throws SQLException {

        ArrayList  arr_estatus= new ArrayList();

        Statement stmt = null;
        ResultSet rs = null;
        String str_codEstatus;
        String str_descEstatus;
        String str_query  = " SELECT codigo_estatus,              " +
                                  "descripcion_estatus            " +
                            " FROM ep_estatus                     " +
                            " WHERE codigo_estatus = 'RCHZ-VPO'OR " +
                            " codigo_estatus = 'PENVPO' OR        " +
                            " codigo_estatus = 'AUTORIZADA'       ";

        stmt = conn.createStatement();
        rs = stmt.executeQuery(str_query);

        while(rs.next()){
            str_codEstatus = rs.getString("codigo_estatus");
            str_descEstatus = rs.getString("descripcion_estatus");

             EstatusBean bn_estatus = new EstatusBean();
             bn_estatus.setStr_codEstatus(str_codEstatus);
             bn_estatus.setStr_descEstatus(str_descEstatus);

             arr_estatus.add(bn_estatus);
        }
        return arr_estatus;
    }
}
